﻿using csLTDMC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace InspectionMAC.SystemThread
{
    class LocationThread
    {
        public static bool LocationContinuous = false;
        public static Thread Location_Thread = null;
        public static UInt32[] LocationCont;
        public static UInt32[] EncoderCont;
        public static double[] dCurrentVel;
        public static void Location_State()
        {
            LocationCont = new UInt32[2];
            EncoderCont = new UInt32[2];
            dCurrentVel = new double[2];

            LocationContinuous = true;
            Location_Thread = new Thread(Location_Run);
            Location_Thread.IsBackground = true;
            Location_Thread.Start();
        }
        private static void Location_Run(object obj)
        {
            while (LocationContinuous)
            {
                ///---這部分是讀第一軸的訊息，(0, 1)這樣為讀取第二軸的，可以直接用數組來做
                LocationCont[0] = LTDMC.dmc_get_position(0, 0);             //读取指定轴0指令位置值
                EncoderCont[0] = LTDMC.dmc_get_encoder(0, 0);             //读取指定轴0的编码器反馈值
                dCurrentVel[0] = LTDMC.dmc_read_current_speed(0, 0);      // 读取轴0当前速度

                LocationCont[1] = LTDMC.dmc_get_position(0, 1);             //读取指定轴1指令位置值
                EncoderCont[1] = LTDMC.dmc_get_encoder(0, 1);             //读取指定轴1的编码器反馈值
                dCurrentVel[1] = LTDMC.dmc_read_current_speed(0, 1);      // 读取轴1当前速度

                Thread.Sleep(1);
            }
        }
    }
}
